-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add support for dronecan and initial GPS driver #11313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: maintenance-10.x
Are you sure you want to change the base?
Conversation
…up Node States message at 1 Hz.
Set Node Status to real data.
…apted for c from https://github.com/ArduPilot/ardupilot/blob/4f4457d259c54bff9a7d909c71e471f7cf1ef8d9/libraries/AP_HAL_ChibiOS/CanIface.cpp Remove redundant call to enable FDCAN clock.
…g messages. Corrected filters for Rx FIFO and correctly read FIFO level for polling.
…ssages in FIFO at initial check so we don't get stuck in the loop. Removed interrupt config code in favour of polling the receive FIFO.
…driver support on the STM32Fxxx series.
…ALs do not support it.
… the MATEKF765SE. Allocate memory for the bxCan write and read messages.
…dle to the CAN instance to avoid a dangling pointer.
…fer and the task reads from the ring buffer. Fix missing include for math.h
Expand dronecan_messages_unittest.cc from 5 to 14 tests covering NodeStatus, Fix v1, Auxiliary, boundary values, and data type verification. Create canard_unittest.cc with 30 tests for the libcanard core: init/node ID, memory pool, CRC-16/CCITT, float16 conversion, transfer ID logic, DLC conversion, single/multi-frame TX, RX frame processing, and pool statistics. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The BatteryInfo message already contains current data which was being stored in dronecanBattSensorGetAmperage(), but this wasn't integrated with INAV's battery metering system. Changes: - Add CURRENT_SENSOR_CAN enum value in battery_config_structs.h - Add case handler in battery.c to read current from DroneCAN - Update settings.yaml to expose CAN option for current_meter_type Users can now select 'CAN' as the current_meter_type in CLI when using DroneCAN-compatible battery sensors. Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Create docs/DroneCAN.md with comprehensive guide covering: - Supported features (GPS, battery voltage/current) - Configuration settings - Hardware setup and wiring - Troubleshooting guide - Message type reference - Update docs/Battery.md current_meter_type table to include all sensor types (ESC, SMARTPORT, CAN) and link to DroneCAN docs Co-Authored-By: Claude Opus 4.6 <[email protected]>
…e Claude forgot to.
The current value from DroneCAN BatteryInfo is in Amps, but INAV's internal amperage unit is centiamps (0.01A). The conversion was multiplying by 10 (giving deciamps) instead of 100 (centiamps). Found during HITL testing: 0.1A applied load showed as 0.01A. Co-Authored-By: Claude Opus 4.6 <[email protected]>
HITL Testing ResultsTested on MATEKF765SE with DroneCAN battery monitor.
Skipped tests: No DroneCAN GPS hardware available. Bug found & fixed: Tests passed:
|
|
I pushed this as ready for review to get feedback from the bots. It is functional at this point but I still want to test with a GPS. |
Review Summary by QodoAdd DroneCAN support with libcanard library and initial GPS driver WalkthroughsDescriptionThis description is generated by an AI tool. It may have inaccuracies. • Adds DroneCAN protocol support to iNav using the libcanard library • Implements initial GPS driver for DroneCAN devices • Includes comprehensive DSDL-generated message definitions for DroneCAN and UAVCAN protocols • Adds DroneCAN driver infrastructure and initialization code • Includes documentation for DroneCAN support • Tested with HITL and CAN current sensor • Resolves issue iNavFlight/inav#11128 • Defers parameter get/set support and CAN error logging to future PRs Diagramflowchart LR
A["iNav Core"] -- "integrates" --> B["DroneCAN Driver"]
B -- "uses" --> C["libcanard Library"]
B -- "implements" --> D["GPS Driver"]
B -- "defines" --> E["DSDL Messages"]
C -- "handles" --> F["CAN Protocol"]
File Changes |
Code Review by Qodo
1. dsdlc_generated code committed
|
| #define CANARD_DSDLC_INTERNAL | ||
| #include "uavcan.equipment.air_data.Sideslip.h" | ||
| #include <string.h> | ||
|
|
||
| #ifdef CANARD_DSDLC_TEST_BUILD | ||
| #include <test_helpers.h> | ||
| #endif | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. dsdlc_generated code committed 📘 Rule violation ⛯ Reliability
This PR adds dsdlc_generated DroneCAN DSDL outputs directly to the repo, which are generated artifacts and can make builds non-reproducible and the repo noisy. These files should be generated into the build directory (or updated via an explicit opt-in step) and excluded from normal source tracking.
Agent Prompt
## Issue description
The PR commits DSDL-generated DroneCAN sources/headers under `dsdlc_generated`, which are generated artifacts.
## Issue Context
Generated artifacts should be produced as part of the build (or via an explicit opt-in update command) and not be committed as normal source to keep the repository clean and reproducible.
## Fix Focus Areas
- src/main/drivers/dronecan/dsdlc_generated/src/uavcan.equipment.air_data.Sideslip.c[1-8]
- cmake/main.cmake[2-12]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Fixes from Qodo code review: 1. RX loop double decrement - removed extra numMessagesToProcess-- that caused half of received messages to be skipped 2. TX queue pop on failure - only pop queue on success (ret > 0), break loop on FIFO full (ret == 0) to retry later 3. F7 transmit return value - return 0 on HAL failure instead of 1, so caller knows transmission failed 4. F7 unique ID - use HAL_GetUIDw0/1/2() instead of HAL_GetDEVID() to get actual per-chip unique ID 5. PG_INAV_END - update to PG_DRONECAN_CONFIG so DroneCAN params are discoverable via MSP parameter group enumeration 6. dronecan.h - add #pragma once and include parameter_group.h to make header self-contained 7. 1Hz timer init - initialize next_1hz_service_at in INIT state to prevent spam at boot Co-Authored-By: Claude Opus 4.6 <[email protected]>
…_GetUIDwX functions. Updating the HAL is a future project.
Address remaining Qodo code review items: 1. Add LOG_DEBUG for decode failures - all message handlers now log when decoding fails, making debugging easier 2. Remove GPS coordinate logging - replaced lat/lon logging with simple "GNSS Fix received" to avoid exposing sensitive location data in debug logs 3. Fix send_NodeStatus buffer size - use NODESTATUS_MAX_SIZE (7) instead of GETNODEINFO_RESPONSE_MAX_SIZE (377) to reduce stack pressure in this frequently-called function Co-Authored-By: Claude Opus 4.6 <[email protected]>
Enable DroneCAN module in SITL builds with stub driver implementation. This is Phase 2.1 of dronecan-sitl-implementation - foundation for SocketCAN integration in Phase 2.2. New files: - src/main/drivers/dronecan/libcanard/canard_sitl_driver.c Stub driver implementing all 7 canardSTM32* functions - Init: Returns success, logs initialization - Transmit: Silently discards frames (no actual CAN yet) - Receive: Returns no frames - Status/FIFO/Recovery: Report healthy/empty state - UniqueID: Returns "SITL" marker Modified files: - src/main/drivers/dronecan/dronecan.c - Remove SITL exclusion (#if !defined(SITL_BUILD)) - Replace HAL_GetTick() with millis() for portability - Add #include "drivers/time.h" for millis() declaration - cmake/sitl.cmake - Add canard_sitl_driver.c to SITL_SRC build list - src/main/target/SITL/target.h - Define USE_DRONECAN to enable DroneCAN for SITL Build verified: - SITL compiles cleanly with USE_DRONECAN enabled - No compilation warnings or linker errors - SITL runs without crash, DroneCAN task initializes Current behavior (stub mode): - TX operations succeed but frames are discarded - RX operations return no frames - No actual CAN communication (expected for Phase 2.1) Phase 2.2 will add SocketCAN implementation for real CAN communication via Linux vcan interfaces. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Adds support for dronecan to Inav with an initial GPS driver example. Dronecan is implemented using libcanard library.
This is a draft PR to see how what the bot feedback is while waiting for my peripherals to arrive. This has not been flown or tested in HITL yet.
Fixes #11128
Add support for Get/Set parametersDeferred to next PRAdd support for logging CAN Rx/Tx errors and bus off events.Deferred to next PR